function maxCoins (piles: number[]): number {
  let count = 0
  piles.sort((a, b) => a - b)
  while (piles.length) {
    piles.pop()
    count += piles.pop()
    piles.shift()
  }
  return count
}

export default function () {
  console.log(maxCoins([9, 5, 6, 8, 10, 1, 4, 10, 7]))
}
